package com.lzw.mysqldemo.mypool;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.lzw.mysqldemo.service.MyObjectFactory;
import org.apache.commons.dbcp2.BasicDataSource;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.sql.Connection;
import java.util.Properties;

public class ObjectPoolMain<T> {

    public static void main(String[] args) throws Exception {

        //======================ObjectPool=========================================
        new org.apache.commons.pool2.impl.GenericObjectPool<Object>(new MyObjectFactory());
        new org.apache.commons.pool.impl.GenericObjectPool<>();


        //======================DBCP===============================================
        BasicDataSource basicDataSource = org.apache.commons.dbcp2.BasicDataSourceFactory.createDataSource(new Properties());
        org.apache.commons.dbcp.BasicDataSourceFactory.createDataSource(new Properties());


        //======================JedisPool==========================================
        JedisPool jedisPool = new JedisPool("127.0.0.1",6379);

        //======================JedisPool重连==========================================
        while (true){
            Thread.sleep(500);
            Jedis jedis = null;
            try {
                jedis = jedisPool.getResource();
                System.out.println(jedis.ping());
            } catch (Exception ex){
                System.out.println("error:"+ex.getCause());
            } finally {
                if(jedis != null){
                    jedis.close();
                }
            }
        }

        //======================druid德鲁伊==========================================
//        Connection connection = DruidDataSourceFactory.createDataSource(new Properties()).getConnection();
//        connection.close();

    }
}
